package com.ruoyi.framework.web.service;

import java.util.List;
import java.util.stream.Collectors;

import com.ruoyi.car.domain.CarBrand;
import com.ruoyi.car.domain.CarCompany;
import com.ruoyi.car.domain.CarSpec;
import com.ruoyi.car.service.ICarBrandService;
import com.ruoyi.car.service.ICarCompanyService;
import com.ruoyi.car.service.ICarSpecService;
import com.ruoyi.common.constant.Constants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.domain.SysDictData;
import com.ruoyi.system.service.ISysDictDataService;
import com.ruoyi.system.service.ISysDictTypeService;

/**
 * BTS首创 html调用 thymeleaf 实现字典读取
 * 
 * @author ruoyi
 */
@Service("dict")
public class DictService
{
    @Autowired
    private ISysDictTypeService dictTypeService;
    @Autowired
    private ISysDictDataService dictDataService;
    @Autowired
    private ICarCompanyService iCarCompanyService;
    @Autowired
    private ICarBrandService iCarBrandService;
    @Autowired
    private ICarSpecService iCarSpecService;

    /**
     * 车辆规格
     * @return
     */
    public List<SysDictData> getTypeCarSpec() {
        CarSpec carSpec = new CarSpec();
        carSpec.setStatus(Constants.SUCCESS);
        return iCarSpecService.selectCarSpecList(carSpec).stream().map(item -> {
            SysDictData sysDictData = new SysDictData();
//            sysDictData.setDictType("car_company");
            sysDictData.setDictValue(item.getId().toString());
            sysDictData.setDictLabel(item.getSpecName());
            return sysDictData;
        }).collect(Collectors.toList());
    }
    /**
     * 汽车品牌
     * @return
     */
    public List<SysDictData>getTypeCarBrand() {
        CarBrand carBrand = new CarBrand();
        carBrand.setStatus(Constants.SUCCESS);
        return iCarBrandService.selectCarBrandList(carBrand).stream().map(item -> {
            SysDictData sysDictData = new SysDictData();
//            sysDictData.setDictType("car_company");
            sysDictData.setDictValue(item.getId().toString());
            sysDictData.setDictLabel(item.getBrandName());
            return sysDictData;
        }).collect(Collectors.toList());
    }
    /**
     * 车企字典值
     * @return
     */
    public List<SysDictData> getTypeCarCompany() {
        CarCompany carCompany = new CarCompany();
        carCompany.setStatus(Constants.SUCCESS);
        return iCarCompanyService.selectCarCompanyList(carCompany).stream().map(item -> {
            SysDictData sysDictData = new SysDictData();
//            sysDictData.setDictType("car_company");
            sysDictData.setDictValue(item.getId().toString());
            sysDictData.setDictLabel(item.getCompanyName());
            return sysDictData;
        }).collect(Collectors.toList());
    }
    /**
     * 根据字典类型查询字典数据信息
     * 
     * @param dictType 字典类型
     * @return 参数键值
     */
    public List<SysDictData> getType(String dictType)
    {
        return dictTypeService.selectDictDataByType(dictType);
    }

    /**
     * 根据字典类型和字典键值查询字典数据信息
     * 
     * @param dictType 字典类型
     * @param dictValue 字典键值
     * @return 字典标签
     */
    public String getLabel(String dictType, String dictValue)
    {
        return dictDataService.selectDictLabel(dictType, dictValue);
    }
}
